package vip.xiaonuo.smzq.modular.jsc.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import vip.xiaonuo.smzq.modular.jsc.entity.Xxlb;
import vip.xiaonuo.smzq.modular.jsc.mapper.XxlbMapper;
import vip.xiaonuo.smzq.modular.jsc.service.IXxlbService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import vip.xiaonuo.common.page.CommonPageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * 驾驶舱消息列表 服务实现类
 *
 * @author sqq
 * @since 2024-05-15
 */
@Service
public class XxlbServiceImpl extends ServiceImpl<XxlbMapper, Xxlb> implements IXxlbService {

    @Resource
    private XxlbMapper xxlbMapper;

    @Override
    public Page<Xxlb> page(Xxlb xxlb) {
        QueryWrapper<Xxlb> queryWrapper = new QueryWrapper<>();
        return this.page(CommonPageRequest.defaultPage(), queryWrapper);
    }

    @Override
    public void add(Xxlb xxlb) {
        if (xxlb.getXzqhdm() != null&&xxlb.getNd() != null&&xxlb.getXxlx() != null){
            xxlbMapper.delete(new QueryWrapper<Xxlb>().eq("xzqhdm",xxlb.getXzqhdm()).eq("nd",xxlb.getNd()).eq("xxlx",xxlb.getXxlx()));
            xxlbMapper.insert(xxlb);
        }
    }

    @Override
    public List<Xxlb> xxlbList(Integer nd, String xzqhDm, Integer xxlx) {
        QueryWrapper<Xxlb> queryWrapper = new QueryWrapper<>();
        if (nd != null){
            queryWrapper.eq("nd",nd);
        }
        if (xzqhDm != null){
            xzqhDm = xzqhDm.replaceAll("0+$", "");
            queryWrapper.like("xzqhdm",xzqhDm);
        }
        if (xxlx != null){
            queryWrapper.eq("xxlx",xxlx);
        }
        return xxlbMapper.selectList(queryWrapper);
    }

    @Override
    public void addRdkc(List<Xxlb> xxlbList) {
        Xxlb xxlb=xxlbList.get(0);
        if (xxlb.getXzqhdm() != null&&xxlb.getNd() != null&&xxlb.getXxlx() != null){
            xxlbMapper.delete(new QueryWrapper<Xxlb>().eq("xzqhdm",xxlb.getXzqhdm()).eq("nd",xxlb.getNd()).eq("xxlx",xxlb.getXxlx()));
            for (Xxlb xxlb1 : xxlbList){
                xxlbMapper.insert(xxlb1);
            }
        }
    }
}
